home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 5.6 KB | 179 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWNotifr.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWNOTIFR_H
- #include "FWNotifr.h"
- #endif
-
- #ifndef FWRECEVR_H
- #include "FWRecevr.h"
- #endif
-
- #ifndef FWNOTIFN_H
- #include "FWNotifn.h"
- #endif
-
- #ifndef FWINTERE_H
- #include "FWIntere.h"
- #endif
-
- #ifndef FWNOTDEF_H
- #include "FWNotDef.h"
- #endif
-
- #ifndef FWTCOLL_H
- #include "FWTColl.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_SPrivInterestReceiver)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_SPrivInterestReceiver)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_SPrivInterestReceiver>
- #pragma template FW_TOrderedCollectionIterator<FW_SPrivInterestReceiver>
-
- #endif
-
- //========================================================================================
- // CLASS FW_MNotifier
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_MNotifier)
- FW_DEFINE_AUTO(FW_MNotifier)
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::FW_MNotifier
- //----------------------------------------------------------------------------------------
-
- FW_MNotifier::FW_MNotifier() :
- fInterestList()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::~FW_MNotifier
- //----------------------------------------------------------------------------------------
-
- FW_MNotifier::~FW_MNotifier()
- {
- // Notify the receivers that this notifier is being deleted
- // (used for instance to remove a RadioCluster when all radio buttons are gone)
- FW_CNotification notifierDeleted(FW_CInterest(this, FW_kNotifierDeletedMsg));
-
- FW_TOrderedCollectionIterator<FW_SPrivInterestReceiver> ite(&fInterestList);
- FW_SPrivInterestReceiver* pair = ite.First();
-
- FW_SOMEnvironment ev;
-
- while (pair)
- {
- // Safer iteration, because the receiver may be deleted in the middle
- // [LSD] Warning: still dangerous in case the notifier has more than 1 interest
- FW_SPrivInterestReceiver* next = ite.Next();
- pair->fReceiver->HandleNotification(ev, notifierDeleted);
- pair = next;
- }
-
- // ----- Delete all left over interest pair
- while ((pair = fInterestList.First()) != NULL)
- {
- // RemoveInterest will call RemoveReceiver
- pair->fReceiver->RemoveInterest(*pair->fInterest);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::Notify
- //----------------------------------------------------------------------------------------
-
- void FW_MNotifier::Notify(Environment* ev, const FW_CNotification ¬ification)
- {
- FW_TOrderedCollectionIterator<FW_SPrivInterestReceiver> ite(&fInterestList);
- FW_SPrivInterestReceiver* pair = ite.First();
- while (pair)
- {
- // Get the next pair before doing any action in case the object is destroyed
- // in the middle (for instance: OK button closing a dialog)
- // [LSD] Warning: still dangerous in case the notifier has more than 1 interest
- FW_SPrivInterestReceiver* next = ite.Next();
-
- if (*pair->fInterest == *notification.GetInterest())
- pair->fReceiver->HandleNotification(ev, notification);
-
- pair = next;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::AddReceiver
- //----------------------------------------------------------------------------------------
-
- void FW_MNotifier::AddReceiver(FW_MReceiver* receiver, FW_CInterest* interest)
- {
- FW_SPrivInterestReceiver* pair = new FW_SPrivInterestReceiver;
- pair->fReceiver = receiver;
- pair->fInterest = interest;
-
- fInterestList.AddLast(pair);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::RemoveReceiver
- //----------------------------------------------------------------------------------------
-
- void FW_MNotifier::RemoveReceiver(FW_MReceiver* receiver, const FW_CInterest& interest)
- {
- FW_SPrivInterestReceiver* pair;
-
- FW_TOrderedCollection<FW_SPrivInterestReceiver> temp;
-
- FW_TOrderedCollectionIterator<FW_SPrivInterestReceiver> ite1(&fInterestList);
- for (pair = ite1.First(); ite1.IsNotComplete(); pair = ite1.Next())
- {
- if (*pair->fInterest == interest && pair->fReceiver == receiver)
- temp.AddLast(pair);
- }
-
- FW_TOrderedCollectionIterator<FW_SPrivInterestReceiver> ite2(&temp);
- for (pair = ite2.First(); ite2.IsNotComplete(); pair = ite2.Next())
- {
- fInterestList.Remove(pair);
- delete pair;
- }
-
- // let the temp::__dt call RemoveAll
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MNotifier::IsConnectedTo
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_MNotifier::IsConnectedTo(FW_MReceiver* receiver, const FW_CInterest& interest)
- {
- FW_SPrivInterestReceiver* pair;
- FW_TOrderedCollectionIterator<FW_SPrivInterestReceiver> ite1(&fInterestList);
- for (pair = ite1.First(); ite1.IsNotComplete(); pair = ite1.Next())
- {
- if (*pair->fInterest == interest && pair->fReceiver == receiver)
- return TRUE;
- }
- return FALSE;
- }